﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
             xmlns:localControls="clr-namespace:SoftSource.Timecard.Entry.Controls"
             xmlns:softSourceControls="clr-namespace:SoftSource.Controls;assembly=SoftSource.Controls.Silverlight"
             xmlns:converters="clr-namespace:SoftSource.Timecard.Entry.Converters"
             xmlns:toolkitControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
             x:Class="SoftSource.Timecard.Entry.Views.EntryView"
             mc:Ignorable="d"
             d:DesignWidth="839"
             d:DesignHeight="511">

    <UserControl.Resources>
        <converters:ProjectIDToCategorySummaryConverter x:Key="ProjectIDToCategorySummaryConverter" />

        <Style x:Key="ImageButtonStyle"
               TargetType="Button">
            <Setter Property="Background"
                    Value="#FF1F3B53" />
            <Setter Property="Foreground"
                    Value="#FF000000" />
            <Setter Property="Padding"
                    Value="3" />
            <Setter Property="BorderThickness"
                    Value="1" />
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1"
                                         StartPoint="0.5,0">
                        <GradientStop Color="#FFA3AEB9"
                                      Offset="0" />
                        <GradientStop Color="#FF8399A9"
                                      Offset="0.375" />
                        <GradientStop Color="#FF718597"
                                      Offset="0.375" />
                        <GradientStop Color="#FF617584"
                                      Offset="1" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="MouseOver" />
                                    <VisualState x:Name="Pressed" />
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="DisabledVisualElement"
                                                                           Storyboard.TargetProperty="Opacity">
                                                <SplineDoubleKeyFrame KeyTime="0"
                                                                      Value=".55" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement"
                                                                           Storyboard.TargetProperty="Opacity">
                                                <SplineDoubleKeyFrame KeyTime="0"
                                                                      Value="1" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused" />
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentPresenter x:Name="contentPresenter"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              Margin="{TemplateBinding Padding}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              Content="{TemplateBinding Content}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}" />
                            <Rectangle x:Name="DisabledVisualElement"
                                       Fill="#FFFFFFFF"
                                       RadiusX="3"
                                       RadiusY="3"
                                       IsHitTestVisible="false"
                                       Opacity="0" />
                            <Rectangle x:Name="FocusVisualElement"
                                       Stroke="#FF6DBDD1"
                                       StrokeThickness="1"
                                       RadiusX="2"
                                       RadiusY="2"
                                       Margin="1"
                                       IsHitTestVisible="false"
                                       Opacity="0" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <toolkitControls:BusyIndicator x:Name="Busy"
                                   HorizontalContentAlignment="Stretch"
                                   VerticalContentAlignment="Stretch">
        <Grid x:Name="LayoutRoot">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <StackPanel Margin="4"
                            Grid.Row="0"
                            Grid.ColumnSpan="2"
                            HorizontalAlignment="Left">
                    <softSourceControls:DateRangeSelector x:Name="EntryDateRangeSelector" />
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Button Content="Refresh"
                                Grid.Column="0"
                                Margin="0,0,3,0"
                                Click="Refresh_Click" />
                        <Button Content="Insert"
                                Grid.Column="1"
                                Margin="3,0,0,0"
                                Click="Insert_Click" />
                    </Grid>
                </StackPanel>

                <data:DataGrid x:Name="EntryDataGrid"
                               Grid.Row="1"
                               AutoGenerateColumns="False"
                               ItemsSource="{Binding Entries.Value}"
                               BeginningEdit="EntryDataGrid_BeginningEdit"
                               RowEditEnded="EntryDataGrid_RowEditEnded">
                    <data:DataGrid.Columns>
                        <data:DataGridTemplateColumn Header="EntryDate"
                                                     SortMemberPath="EntryDate">
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding EntryDate, Converter={StaticResource FormattedDateConverter}}"
                                               Margin="3,0,3,0"
                                               VerticalAlignment="Center"
                                               HorizontalAlignment="Left" />
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                            <data:DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <controls:DatePicker VerticalAlignment="Center"
                                                         SelectedDate="{Binding EntryDate, Mode=TwoWay}" />
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellEditingTemplate>
                        </data:DataGridTemplateColumn>
                        <data:DataGridTemplateColumn Header="Project">
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding ProjectID, Converter={StaticResource ProjectIDConverter}, ConverterParameter=Name}"
                                               Margin="3,0,3,0"
                                               VerticalAlignment="Center"
                                               HorizontalAlignment="Left" />
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                            <data:DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <localControls:ProjectComboBox VerticalAlignment="Center"
                                                                   ProjectID="{Binding ProjectID, Mode=TwoWay}" />
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellEditingTemplate>
                        </data:DataGridTemplateColumn>
                        <data:DataGridTemplateColumn Header="Category">
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding CategoryID, Converter={StaticResource CategoryIDConverter}, ConverterParameter=Name}"
                                               Margin="3,0,3,0"
                                               VerticalAlignment="Center"
                                               HorizontalAlignment="Left" />
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                            <data:DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <localControls:CategoryComboBox VerticalAlignment="Center"
                                                                    ItemsSource="{Binding ProjectID, Converter={StaticResource ProjectIDToCategorySummaryConverter}}"
                                                                    CategoryID="{Binding CategoryID, Mode=TwoWay}" />
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellEditingTemplate>
                        </data:DataGridTemplateColumn>
                        <data:DataGridTextColumn Header="Hours"
                                                 Binding="{Binding Duration}" />
                        <data:DataGridCheckBoxColumn Header="Overnight Stay"
                                                     Binding="{Binding OvernightStay}" />
                        <data:DataGridTemplateColumn MaxWidth="300"
                                                     Header="Description"
                                                     SortMemberPath="Description">
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Description}"
                                               TextWrapping="Wrap"
                                               Margin="3,0,3,0"
                                               VerticalAlignment="Center" />
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                            <data:DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <TextBox Text="{Binding Description, Mode=TwoWay}"
                                             AcceptsReturn="True"
                                             TextWrapping="Wrap"
                                             MaxLength="255" />
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellEditingTemplate>
                        </data:DataGridTemplateColumn>
                        <data:DataGridTextColumn Header="Billing Status"
                                                 IsReadOnly="True"
                                                 Binding="{Binding BillingStateID, Converter={StaticResource BillingStateIDConverter}, ConverterParameter=Name}" />
                        <data:DataGridTemplateColumn>
                            <data:DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <Border>
                                        <Button Click="Edit_Click"
                                                Style="{StaticResource ImageButtonStyle}">
                                            <Image Source="/SoftSource.Timecard.Entry;Component/Images/pencil.png" />
                                        </Button>
                                    </Border>
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellEditingTemplate>
                        </data:DataGridTemplateColumn>
                        <data:DataGridTemplateColumn>
                            <data:DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <Border>
                                        <Button Click="Delete_Click"
                                                Style="{StaticResource ImageButtonStyle}">
                                            <Image Source="/SoftSource.Timecard.Entry;Component/Images/delete.png" />
                                        </Button>
                                    </Border>
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellEditingTemplate>
                        </data:DataGridTemplateColumn>
                    </data:DataGrid.Columns>
                </data:DataGrid>
            </Grid>
        </Grid>
    </toolkitControls:BusyIndicator>
</UserControl>
